package com.ruoyi.drug.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.drug.domain.DrugInoutRecord;
import com.ruoyi.drug.service.IDrugInoutRecordService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 药品出入记录Controller
 * 
 * @author ruoyi
 * @date 2025-03-25
 */
@RestController
@RequestMapping("/record")
public class DrugInoutRecordController extends BaseController
{
    @Autowired
    private IDrugInoutRecordService drugInoutRecordService;

    /**
     * 查询药品出入记录列表
     */
    @RequiresPermissions("drug:record:list")
    @GetMapping("/list")
    public TableDataInfo list(DrugInoutRecord drugInoutRecord)
    {
        startPage();
        List<DrugInoutRecord> list = drugInoutRecordService.selectDrugInoutRecordList(drugInoutRecord);
        return getDataTable(list);
    }

    /**
     * 导出药品出入记录列表
     */
    @RequiresPermissions("drug:record:export")
    @Log(title = "药品出入记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DrugInoutRecord drugInoutRecord)
    {
        List<DrugInoutRecord> list = drugInoutRecordService.selectDrugInoutRecordList(drugInoutRecord);
        ExcelUtil<DrugInoutRecord> util = new ExcelUtil<DrugInoutRecord>(DrugInoutRecord.class);
        util.exportExcel(response, list, "药品出入记录数据");
    }

    /**
     * 获取药品出入记录详细信息
     */
    @RequiresPermissions("drug:record:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(drugInoutRecordService.selectDrugInoutRecordById(id));
    }

    /**
     * 新增药品出入记录
     */
    @RequiresPermissions("drug:record:add")
    @Log(title = "药品出入记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DrugInoutRecord drugInoutRecord)
    {
        return toAjax(drugInoutRecordService.insertDrugInoutRecord(drugInoutRecord));
    }

    /**
     * 修改药品出入记录
     */
    @RequiresPermissions("drug:record:edit")
    @Log(title = "药品出入记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DrugInoutRecord drugInoutRecord)
    {
        return toAjax(drugInoutRecordService.updateDrugInoutRecord(drugInoutRecord));
    }

    /**
     * 删除药品出入记录
     */
    @RequiresPermissions("drug:record:remove")
    @Log(title = "药品出入记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(drugInoutRecordService.deleteDrugInoutRecordByIds(ids));
    }
}
